/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author Derek
 */
public class CourseServlet extends HttpServlet {
   
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    String[] courseSubject ={"CPSC","CPSC","ASTR"};
    String[] courseCode ={"410","415","101"};
    String[] courseTitle={"Advanced Software Engineering",
                          "Advanced Operating System",
                          "Intro to Astr:Solar System"};
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
        
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet CourseServlet</title>");  
            out.println("</head>");
            out.println("<body>");
            
            out.println("<center>");
            
            out.println("<form name=\"courseDeletion\" action=\"CourseServlet\" mehotd=\"POST\">");
            out.println("<table>");
            for(int i=0;i<courseSubject.length;i++){
            out.println(
            "<tr>"+
            "   <td>"+
            "   <a href=CourseNewsGroupServlet?courseSubject="+courseSubject[i]+"&courseCode="+courseCode[i]+">" + courseSubject[i] +" " +courseCode[i] + " " + courseTitle[i] + "</a> " +
            "   </td>"+
            "    <td> " +
            "      <button onclick=\"window.open('CourseNewsGroupServlet?courseSubject="+courseSubject[i]+"&courseCode="+courseCode[i]+"')\">Enter</button>" +
            "    </td>"+        
            "    <td> " +
            "      <input type=\"submit\" name=\"" + i +"\" value=\"Delete\" >" +
            "    </td>"+
            "</tr>"
            );
            }
            //out.println();
            
            
            
            out.println("</table>");
            out.println("</form>");
            out.println("<center>");
            
            
            out.println("</body>");
            out.println("</html>");
        
        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
